package com.situ.blog.service.impl;


import com.situ.blog.dao.IUserDao;
import com.situ.blog.dao.impl.UserDaoImpl;
import com.situ.blog.pojo.entity.User;
import com.situ.blog.pojo.query.UserQuery;
import com.situ.blog.service.IUserService;
import com.situ.blog.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserDao userDao;

    //业务：为了封装PageInfo，查询两次数据库
    @Override
    public LayUITableResult selectByPage(UserQuery userQuery) {
        List<User> list = userDao.selectByPage(userQuery);
        Integer totalCount = userDao.selectTotalCount(userQuery);

        return LayUITableResult.ok(totalCount, list);
    }

    @Override
    public void deleteById(User user) {
        userDao.deleteById(user);
    }

    @Override
    public void add(User user) {
        userDao.add(user);
    }

    @Override
    public User login(String name, String password) {
        return userDao.login(name, password);
    }


    /*@Override
    public void deleteAll(String[] ids) {
        // delete from user where id in();
        int count = 0;
        for (String id : ids) {
            count += userDao.deleteById(Integer.parseInt(id));
        }
    }*/

    @Override
    public void updateStatus(int id, int status) {
        userDao.updateStatus(id, status);
    }
}
